/*///////////////////////////////////////////////////////////////// P L A S M A (C version) =========== tek_hed Hi. This is tek_hed. I am 15 years old and getting very bored of the limitations of QuickBASIC. I have begun to program in C some time ago, but decided it to be too complex and mystifiying(sp?). Now I decided it was time to bite the bullet. This is what came out. PLASMA. A cheap name but I didn't know what DEMO effect to call it after. It seems the closest it resembles. After seeing some plasma effects in demos, I found the palette rotating effect to be rather boring, and all in all the same. I never got to respect the effect, until I actually decided to make it myself. I owe great thanks to Jeremy Longley's source code of JCLPLASMA. (Great demo! btw). The loooooong formula (trig and stuff) is not my creation. To this I admit but I do understand how it is that it works. It would take too long to explain it, but if you really want to know, then get a good math text-book and start reading up on Trigonometry. (sine, cosine, tangent...) Notes: This is **NOT** a very optimized version. Infact, I tried to make LUT's (Look Up Tables) for the square (n^2) values, but for some reason I wasn't able to (int's and floats don't get along very well :| ). Also, this was compiled in Borland Turbo C v3.00 using the Large memory model. Hope you have fun! - tek_hed 5-16-97 email: tek_hed@hotmail.com *////////////////////////////////////////////////////////////////// ////////////////////////////////////////// // headers /////////////////////////////// ////////////////////////////////////////// #include #include #include ////////////////////////////////////////// // globals /////////////////////////////// ////////////////////////////////////////// int val, red,grn,blu, red_d,grn_d,blu_d, dummy, original_red[255], original_grn[255], original_blu[255], useable[6]={1,-1,3,-3,1,1}; float mag,v,x, y; double a; char check_char; ////////////////////////////////////////// // void declerations ///////////////////// ////////////////////////////////////////// void exitprog(void); ////////////////////////////////////////// // voids ///////////////////////////////// ////////////////////////////////////////// ////////////////////////////////////////// // wait for vsync ////////////////////////////////////////// void vsync() { while(inp(0x3da)&8){}; while(!(inp(0x3da)&8)){}; }// end void ////////////////////////////////////////// // set pallete (color c = r,g,b) ////////////////////////////////////////// void set_pal(int c, int r, int g, int b) { outp(0x3C8, c); outp(0x3C9, r); outp(0x3C9, g); outp(0x3C9, b); } ////////////////////////////////////////// // save palette ////////////////////////////////////////// void save_pal() { int temp; for (temp=0;temp<256;temp++){ outp(0x3c7,temp); original_red[temp]=inp(0x3c9); original_grn[temp]=inp(0x3c9); original_blu[temp]=inp(0x3c9); } }// end void ////////////////////////////////////////// // restore palette to original ////////////////////////////////////////// void restore_pal() { int temp; for (temp=0;temp<256;temp++) { set_pal(temp,original_red[temp], original_grn[temp], original_blu[temp]); } } // end void ////////////////////////////////////////// // rotate palette ////////////////////////////////////////// void rot_pal() { int temp; vsync(); for (temp=0;temp<256;temp++){ red+=red_d; if (red>62) red_d=-abs(red_d); if (red<2) red_d=abs(red_d); grn+=grn_d; if (grn>62) grn_d=-abs(grn_d); if (grn<2) grn_d=abs(grn_d); blu+=blu_d; if (blu>62) blu_d=-abs(blu_d); if (blu<2) blu_d=abs(blu_d); set_pal(temp,red,grn,blu); } }//end void ////////////////////////////////////////// // set 13h gfx mode (320x200x256) ////////////////////////////////////////// void mode13() { asm mov ah,0 //set mode asm mov al,13h //to 320x200x256 (mode 13) asm int 10h //using int 10 }// end void ////////////////////////////////////////// // set 03h gfx mode (80x25x16) ////////////////////////////////////////// void mode03() { asm mov ah,0 //set mode asm mov al,03h //to 80x25x16 (mode 3) asm int 10h //using int 10 }// end void ////////////////////////////////////////// // Draw a dot in 13h ////////////////////////////////////////// void dot(int x, int y, char c) { //use offset=y*320+x -> offset=y*(64+256)+x -> offset = y<<8 + y<<7 +x asm mov ax,y asm mov bx,ax asm shl ax,8 asm shl bx,6 asm add bx,ax asm add bx,x asm mov ax,0xa000 asm mov es,ax asm mov al,c asm mov es:[bx],al } // end void ////////////////////////////////////////// // draw plasma gfx in 13h (320x200x256) ////////////////////////////////////////// void DrawPlas() { float xx,yy; for (y=0;y<=100;y++) { for (x=0;x<=319;x++) { //bottom -> up xx=x; yy=200-y; val=50*( sin(xx*mag/30) + cos(yy*mag/16) + cos(xx*mag/17) + sin(yy*mag/10) + cos(((xx*mag-160)+(yy*mag-100))/13) + hypot((xx-160)*mag,(yy-120)*mag)/50 ); dot((int)xx,(int)yy,(int)val); //top -> bottom xx=x; yy=y; val=50*( sin(x*mag/30) + cos(y*mag/16) + cos(x*mag/17) + sin(y*mag/10) + cos(((x*mag-160)+(y*mag-100))/13) + hypot((x-160)*mag,(y-120)*mag)/50 ); dot((int)xx,(int)yy,(int)val); }// end x }//end y } // end void ////////////////////////////////////////// // main ////////////////////////////////// ////////////////////////////////////////// void main() { //give values to the globals red_d=3; // \ grn_d=3; // > the r/g/b deltas 3,3,1 || -1,3,3 || 3,1,0 are the best blu_d=1; // / dummy=1; // dummy var to keep a while statement true // .: an infinite loop is formed mag=3; // magnigication of gfx mode13(); //set screen save_pal(); //save the palette rot_pal(); //make the first color rotation DrawPlas(); //draw the static gfx do { vsync(); rot_pal(); if (kbhit()) { check_char = getch(); if (check_char==32) { red_d=useable[random(6)+1]; grn_d=useable[random(6)+1]; blu_d=useable[random(6)+1]; red=red_d; grn=grn_d; blu=blu_d; }; if (check_char==27) { exitprog(); exit(-1); }; } //end kbhit } while (check_char!=27); } // end main void exitprog() { restore_pal(); mode03(); printf("PLASMA (C version)\n"); printf("by tek_hed\n"); printf("email: tek_hed@hotmail.com\n"); printf("www: http://tek-hed.base.org\n"); }